package com.lmm.lcuser.lc_user;


import com.lmm.dresswisdom.lmmframe.util.FileUtils;
import com.lmm.dresswisdom.lmmframe.util.ToastUtils;
import com.lmm.lcuser.lc_user.plugins.UploadCallBack;
import com.qiniu.android.http.ResponseInfo;
import com.qiniu.android.storage.UpCompletionHandler;
import com.qiniu.android.storage.UploadManager;

import org.json.JSONObject;

import java.io.File;

/**
 *
 * @author xmgong
 * @date 2017/10/31
 * 相关复杂操作
 */

public class ReactNativePresent {
    /**
     * 上传图片
     * @param token
     * @param filetag
     * @param mfile
     * @param uploadCallBack
     */
    public static void uploadImg( String token, String filetag ,File mfile, final UploadCallBack uploadCallBack) {
        UploadManager uploadManager = new UploadManager();
        final String filename = FileUtils.getDateFileName(mfile.getName(), filetag);
        uploadManager.put(mfile, filename, token, new UpCompletionHandler() {
            @Override
            public void complete(String key, ResponseInfo info, JSONObject response) {
                if (info.isOK()) {
                    ToastUtils.showToastShort("上传成功");
                    uploadCallBack.uploadFinish(filename);
                } else {
                    ToastUtils.showToastShort("图片上传失败");
                }
            }
        }, null);
    }

}
